package com.treasure.mall.biz.entity.order;

import com.treasure.mall.biz.entity.user.MerchantPO;
import com.treasure.mall.zbq.common.ienum.order.OrderEnums;
import com.treasure.mall.zbq.common.ienum.product.ProductEnums;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.math.BigDecimal;

/**
 * 业务订单，一些增值业务
 * 比如充值，升级服务
 *
 * @author allan
 * @version 1.0.0
 * @date 2020/6/14
 */
@Entity
@Table(name = "zb_biz_order")
@Setter
@Getter
public class BizOrderPO extends OrderPO {
    /**
     * 业务类型
     */
    @Column(name = "deal_type")
    private OrderEnums.DealType dealType;
    /**
     * 关联商品
     */
    @Column(name = "goods_id")
    private Long goodsId;
    @Column(name = "goods_bn")
    private String goodsBn;
    @Column(name = "goods_name")
    private String goodsName;
    /**
     * 零售价格
     */
    @Column(name = "price", scale = 2, precision = 10)
    private BigDecimal price;
    @Column(name = "product_type")
    private ProductEnums.ProductType productType;
    /**
     * 商品缩略图
     */
    @Column(name = "thumbnail")
    private String thumbnail;
    /**
     * 属于哪个直播间
     */
    @Column(name = "room_id")
    private Long roomId;
    @Column(name = "room_name")
    private String roomName;

    /**
     * 关联的拍卖
     */
    @Column(name = "auction_session_id")
    private Long auctionSessionId;

    @Column(name = "payment_bill_id")
    private String paymentBillId;
    @Column(name = "after_sale_status")
    private OrderEnums.AfterSaleStatus afterSaleStatus;
    /**
     * 直播场次
     */
    @Column(name = "live_session_id")
    private String liveSessionId;
    @ManyToOne
    @JoinColumn(name = "rel_merchant_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    private MerchantPO merchantPO;

    public boolean enableRefund() {
        return (afterSaleStatus == null || afterSaleStatus == OrderEnums.AfterSaleStatus.FAILED)
                && payStatus == OrderEnums.PayStatus.PAYED;
    }
}
